package com.itany.corejava.code07_面向对象.bms;

/**
 * @author 石小俊
 * @date 2023年04月21日 16:08
 * 贷款的信用账户
 */
public class LoanCreditAccount extends CreditAccount implements Loanable {

    private double loanAmount;

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }

    @Override
    public void providerLoan(double money) {
        loanAmount += money;
    }

    @Override
    public boolean payLoan(double money) {
        // 对于贷款的信用账户
        // 只有账户余额+可透支额度 >= 还贷金额,才可以成功还款
        if (getBalance() + getLimit() >= money) {
            // 还贷后当前账户余额减少
            setBalance(getLoanAmount() - money);
            // 剩余贷款金额减少
            loanAmount -= money;
            return true;
        }
        return false;
    }

    @Override
    public double queryLoan() {
        return this.loanAmount;
    }
}
